package course.d1230;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/*
    接收端步骤：
    1.创建DataGramSocket对象,指定端口号
    2.接收数据
    3.拆包
 */
public class a5 {
    public static void main(String[] args) throws IOException {

        DatagramSocket socket = new DatagramSocket(8888);

        byte[] bs = new byte[1024];
        DatagramPacket datagramPacket = new DatagramPacket(bs, bs.length);
        socket.receive(datagramPacket);

        byte[] data = datagramPacket.getData();
        int length = datagramPacket.getLength();
        System.out.println("数据:   "+new String(data,0,length));

    }
}
